package com.Redis.Server;

import java.util.Properties;

import org.apache.log4j.Logger;
import org.aspectj.weaver.patterns.ThisOrTargetAnnotationPointcut;
import org.springframework.stereotype.Service;

import com.Redis.Model.ReportData;
import com.Redis.Utils.PropertiesUtil;
import com.Redis.Utils.RequestUtil;

/**
 * 
 * @author Ren
 * 调用测评报告的接口
 */
@Service
public class ApiReportServer{
	private Logger logger = Logger.getLogger(this.getClass().getName());
	private String reportpath = null;
	
	private static ApiReportServer instance;  
    
	private ApiReportServer(){
    	Properties prop = PropertiesUtil.getConProp();
	    this.reportpath = prop.getProperty("reportpath");
    }   
    //线程安全的单例模式
	public static ApiReportServer getInstance(){    //对获取实例的方法进行同步
      if (instance == null){
          synchronized(ApiReportServer.class){
              if (instance == null)
                  instance = new ApiReportServer(); 
          }
      }
      return instance;
    }
	
	
	// 获取报告数据
    public String getReportJsonData(ReportData reportData) {
		String jsondata = null;			
		StringBuilder sb = new StringBuilder();
		sb.append( this.reportpath);
		sb.append("school/report/generateReportjson?subject_id=");
		sb.append(reportData.getSubjectId());
		sb.append("&student_id=");
		sb.append(reportData.getStudentId());
		sb.append("&courseid=");
		sb.append(reportData.getCourseId());
		sb.append("&groupid=");
		sb.append(reportData.getGroupId());
		sb.append("&classid=");
		sb.append(reportData.getClassId());
		sb.append("&type=1");
		
		logger.info("------HTTPURL------"+sb.toString());		
		jsondata = RequestUtil.getResult(sb.toString(),"");		
		return jsondata;
    	
	}
	
}
